

/**
 * @author Carlos
 * @version 1.0
 * @created 09-oct-2013 05:23:48 p.m.
 */
using System.Xml;
using Imaginarium.XML;
using System;
namespace Imaginarium.stats
{
    public class BaseDamage:
        ICloneable
    {
        public int aoe { get; set; }
        public bool ignoreDodge { get; set; }
        public int ignoreMgcArmor { get; set; }
        public int ignorePhyArmor { get; set; }
        public int damage { get; set; }
        public bool isMagic { get; set; }
        public Elemental elementalDamage { get; set; }

        public BaseDamage()
        {

        }

        public BaseDamage(XmlElement element)
        {
            this.aoe = XmlHelper.getIntByTagname(element, XmlParameters.BASE_DAMAGE_AOE);
            this.ignoreDodge = XmlHelper.getBoolByTagname(element, XmlParameters.BASE_DAMAGE_IGNORE_DODGE);
            this.ignoreMgcArmor= XmlHelper.getIntByTagname(element, XmlParameters.BASE_DAMAGE_IGNORE_MAG_ARMOR);
            this.ignorePhyArmor = XmlHelper.getIntByTagname(element, XmlParameters.BASE_DAMAGE_IGNORE_PHY_ARMOR);
            this.damage = XmlHelper.getIntByTagname(element, XmlParameters.BASE_DAMAGE_PHYSIC_DAMAGE);
            this.elementalDamage = new Elemental(XmlHelper.getXmlElementByTagname(element,XmlParameters.ELEMENTAL));
        }

        public int getNonElementalBaseDmg() 
        {
            int nonElementalBaseDmg = 0;
            if (!hasElementalDmg())
                nonElementalBaseDmg = damage;
            else if (elementalDamage.isPercentage)
                nonElementalBaseDmg = (int)(damage * (1 - elementalDamage.earth - elementalDamage.fire - elementalDamage.water - elementalDamage.wind));
            else
                nonElementalBaseDmg = damage;
            return nonElementalBaseDmg;
        }

        public bool hasElementalDmg() 
        {
            if (elementalDamage == null || elementalDamage.earth <= 0 && elementalDamage.fire <= 0 && elementalDamage.water <= 0 && elementalDamage.wind <= 0)
                return false;
            return true;
        }

        #region ICloneable Members

        public object Clone()
        {
            BaseDamage newBaseDamage = (BaseDamage)base.MemberwiseClone();
            newBaseDamage.elementalDamage = (Elemental)this.elementalDamage.Clone();
            return newBaseDamage;
        }

        #endregion
    }
}